import React, {Component} from 'react';
import '../../static/scss/routes.scss'
import '../../static/scss/fileViewer/viewer.scss'
import PdfViewerApp from "./pdfViewerApp";
import ExcelViewerApp from "./excelViewerApp";
import WordViewerApp from "./wordViewerApp";
import PowerPointViewerApp from "./powerPointViewerApp";
import {Route, Switch} from "react-router";
import NotFound from "../notFound/notFound";
import TxtViewerApp from "./txtViewerApp";
import JsonViewerApp from "./jsonViewerApp";
import XmlViewerApp from "./xmlViewerApp";
import commonConfig from "../../static/js/commonConfig";

class ViewerApp extends Component {
    state = {
        routes: [
            {path: 'pdfViewer', component: PdfViewerApp},
            {path: 'excelViewer', component: ExcelViewerApp},
            {path: 'wordViewer', component: WordViewerApp},
            {path: 'powerPointViewer', component: PowerPointViewerApp},
            {path: 'txtViewer', component: TxtViewerApp},
            {path: 'jsonViewer', component: JsonViewerApp},
            {path: 'xmlViewer', component: XmlViewerApp},
        ]
    }

    componentWillMount() {
        if (!commonConfig.judgeUserLoginStatus()) {
            commonConfig.redirectPageDefault(this, "login");
        }
    }

    render() {
        const {routes} = this.state;

        const path = '/viewer'
        return (
            <>
                <div className="system_container viewer_module">
                    <Switch>
                        {routes.map((item, i) =>
                            <Route key={i} path={`${path}/${item.path}`}
                                   component={props => <item.component {...props}/>}/>
                        )}
                        <Route path="*" component={props => <NotFound {...props}/>}/>
                    </Switch>
                </div>
            </>
        )
    }

}

export default ViewerApp